using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FlashEffect : MonoBehaviour
{
    [SerializeField]
    private Transform m_Light;
    [Range(0, 10)]
    public float interval;
    [Range(0.1f, 10)]
    public float duration;

    public Vector3 m_StartPosition = new Vector3(-0.8f, 0, 0);
    public Vector3 m_EndPosition = new Vector3(0.8f, 0, 0);
    #region Public方法

    #endregion

    #region Private方法
    private IEnumerator Coroutine()
    {
        m_Light.position = m_StartPosition;
        float endTime;
        float lerp;
        Vector3 newPosition = Vector3.zero;
        while (true)
        {
            endTime = Time.time + duration;
            lerp = 0;
            while (Time.time < endTime)
            {
                yield return null;
                lerp += Time.deltaTime / duration;
                newPosition.x = Mathf.Lerp(m_StartPosition.x, m_EndPosition.x, lerp);
                newPosition.y = Mathf.Lerp(m_StartPosition.y, m_EndPosition.y, lerp);
                newPosition.z = Mathf.Lerp(m_StartPosition.z, m_EndPosition.z, lerp);
                m_Light.localPosition = newPosition;
            }
            yield return new WaitForSeconds(interval);
        }
    }
    #endregion

    #region Unity方法
    private void OnEnable()
    {
        StartCoroutine(Coroutine());
    }
    #endregion
}